package com.example.concurrency.xx.thread;

import java.util.HashMap;
import java.util.Hashtable;

/**
 * @author: dangwen
 * @createDate: 2021/2/3
 */
public class ThreadLocalDemo {

    static ThreadLocal<Integer> threadLocal = new ThreadLocal<Integer>(){
        @Override
        protected Integer initialValue() {
            return 1;
        }
    };

    static class MyThread implements Runnable{
        @Override
        public void run() {
            Integer integer = threadLocal.get();
            threadLocal.set(integer++);
            threadLocal.remove();
            System.out.println(Thread.currentThread().getName()+"-------"+integer);
        }
    }

    public static void main(String[] args) {
        MyThread myThread = new MyThread();

//        for (int i = 0; i < 5; i++){
//            new Thread(myThread).start();
//        }
        HashMap map = new HashMap();
        map.put(null,1);
        Object o = map.get(null);
        System.out.println(o);
//        Hashtable hashtable = new Hashtable();
//        hashtable.put(null,null);
        SDemo sDemo = new SDemo(){
            @Override
            Integer showName() {
                return 5;
            }
        };
        System.out.println(sDemo.showName());
    }
}


class SDemo{

    Integer showName(){
        return 111;
    }
}
